import subprocess
import sys

visualCflags, visualCflagse = subprocess.Popen(["pkg-config", "--cflags", "libvisual-0.4"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

if visualCflagse:
    print visualCflagse
    sys.exit(0)

env = Environment(CCFLAGS = Split("-g -Wall") + Split(visualCflags));

visualLdflags, visualLdflagse = subprocess.Popen(["pkg-config", "--libs", "libvisual-0.4"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

if visualLdflagse:
    print visualLdflagse
    sys.exit(0)

libs = env.ParseFlags(Split(visualLdflags))
env.MergeFlags(libs)

arch, _ = subprocess.Popen(['arch'], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

loop = ''
if arch.find('86') >= 0:
    loop = "loopx86.s"
else:
    loop = "loop.c"

files = Split("actor_blursk.c bitmap.c blur.c blursk.c " + \
    "color.c img.c render.c text.c config.c paste.c " + loop)

plugin = env.SharedLibrary(files)

env.Install('/usr/lib/libvisual-0.4/actor/', plugin)
env.Alias('install', '/usr/lib/libvisual-0.4/actor')
